package com.honeyms.project.blog.blogcontentdetail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.honeyms.framework.aspectj.lang.annotation.Log;
import com.honeyms.framework.aspectj.lang.enums.BusinessType;
import com.honeyms.project.blog.blogcontentdetail.domain.BlogContentDetail;
import com.honeyms.project.blog.blogcontentdetail.service.IBlogContentDetailService;
import com.honeyms.framework.web.controller.BaseController;
import com.honeyms.framework.web.domain.AjaxResult;
import com.honeyms.common.utils.poi.ExcelUtil;
import com.honeyms.framework.web.page.TableDataInfo;

/**
 * 帖子详情Controller
 * 
 * @author honeyms
 * @date 2020-10-12
 */
@Controller
@RequestMapping("/blog/blogcontentdetail")
public class BlogContentDetailController extends BaseController
{
    private String prefix = "blog/blogcontentdetail";

    @Autowired
    private IBlogContentDetailService blogContentDetailService;

    @RequiresPermissions("blog:blogcontentdetail:view")
    @GetMapping()
    public String blogcontentdetail()
    {
        return prefix + "/blogcontentdetail";
    }

    /**
     * 查询帖子详情列表
     */
    @RequiresPermissions("blog:blogcontentdetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BlogContentDetail blogContentDetail)
    {
        startPage();
        List<BlogContentDetail> list = blogContentDetailService.selectBlogContentDetailList(blogContentDetail);
        return getDataTable(list);
    }

    /**
     * 导出帖子详情列表
     */
    @RequiresPermissions("blog:blogcontentdetail:export")
    @Log(title = "帖子详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BlogContentDetail blogContentDetail)
    {
        List<BlogContentDetail> list = blogContentDetailService.selectBlogContentDetailList(blogContentDetail);
        ExcelUtil<BlogContentDetail> util = new ExcelUtil<BlogContentDetail>(BlogContentDetail.class);
        return util.exportExcel(list, "blogcontentdetail");
    }

    /**
     * 新增帖子详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存帖子详情
     */
    @RequiresPermissions("blog:blogcontentdetail:add")
    @Log(title = "帖子详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BlogContentDetail blogContentDetail)
    {
        return toAjax(blogContentDetailService.insertBlogContentDetail(blogContentDetail));
    }

    /**
     * 修改帖子详情
     */
    @GetMapping("/edit/{contentDetailId}")
    public String edit(@PathVariable("contentDetailId") Long contentDetailId, ModelMap mmap)
    {
        BlogContentDetail blogContentDetail = blogContentDetailService.selectBlogContentDetailById(contentDetailId);
        mmap.put("blogContentDetail", blogContentDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存帖子详情
     */
    @RequiresPermissions("blog:blogcontentdetail:edit")
    @Log(title = "帖子详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BlogContentDetail blogContentDetail)
    {
        return toAjax(blogContentDetailService.updateBlogContentDetail(blogContentDetail));
    }

    /**
     * 删除帖子详情
     */
    @RequiresPermissions("blog:blogcontentdetail:remove")
    @Log(title = "帖子详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(blogContentDetailService.deleteBlogContentDetailByIds(ids));
    }
}
